package com.example.hssmgs.Student;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class DBOpenHelper extends SQLiteOpenHelper {

    public DBOpenHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // 创建学生信息表语句
//        String sql_student_db = "create table student_db(account varchar(20), id varchar(20))";
        String sql_student_db = "create table student_db(\n" +
                "id varchar(12),\n" +
                "sname varchar(12),\n" +
                "age int,\n" +
                "class varchar(20),\n" +
                "sex varchar(10) CHECK(sex='男' OR sex='女') DEFAULT ('男'),\n" +
                "brith datetime,\n" +
                "clubInfo varchar(20) DEFAULT('无') ,\n" +
                "awards varchar(100) DEFAULT('无'),\n" +
                "graduationWork VARCHAR(50) DEFAULT('在校中')\n" +
                ")";
        // 学生密码表
        String sql_student_pw = "create table student_pw(account varchar(20), password varchar(20))";


        db.execSQL(sql_student_db);
        db.execSQL(sql_student_pw);

        String sql_insert_pw1 = "insert into student_pw values ('2220710149', '123456'), ('2', 'haha')";
        String sql_insert_db1 = "\n" +
                "insert into student_db (id,sname,age,class,sex,brith)values ('2220710149', '易政', 23,'计算机科学与技术Z-1班','男','1999-07-12')";
//        String sql_insert_db1 = "\n" +
//                "insert into student_db values ('2220710149', '易政', 23,'计算机科学与技术Z-1班','男','1999-07-12','无','无','在校中')";
//
//
        db.execSQL(sql_insert_pw1);
        db.execSQL(sql_insert_db1);



        // 创建老师信息表语句
        String sql_teacher_db = "create table teacher_db(id varchar(20), name varchar(20))";
        // 创建老师密码
        String sql_teacher_pw = "create table teacher_pw(account varchar(20), password varchar(20))";

        db.execSQL(sql_teacher_db);
        db.execSQL(sql_teacher_pw);

        String sql_insert_db2 = "insert into teacher_db values ('t1', 'teacher1')";
        String sql_insert_pw2 = "insert into teacher_pw values ('t1', 't1'), ('t2', 't2')";

        db.execSQL(sql_insert_db2);
        db.execSQL(sql_insert_pw2);


//        // 管理员账户
//        String sql_admin_db = "create table admin_db(id varchar(20))";
        // 管理员密码表
        String sql_admin_pw = "create table admin_pw(account varchar(20), password varchar(20))";



//        db.execSQL(sql_admin_db);
        db.execSQL(sql_admin_pw);

//        String sql_insert_db3 = "insert into admin_db values ('root', 'admin')";
        String sql_insert_pw3 = "insert into admin_pw values ('root', 'root')";

//        db.execSQL(sql_insert_db3);
        db.execSQL(sql_insert_pw3);


//        留言信息存储表
        String sql_left_msg  = "create table message(teacher_id varchar(20), student_id varchar(20), message text)";
        db.execSQL(sql_left_msg);


    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
